package com.yunxi.controller.activiti;

import com.github.pagehelper.PageInfo;

import com.yunxi.activiti.pojo.ActivitiTypeVO;
import com.yunxi.activiti.service.ActivitiTypeDubboService;
import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Created by leed on 2018/11/19.
 */
@RestController
@RequestMapping("/admin/activitiType")
@Api(tags = "activiti:type", description = "工作流类型接口")
public class ActivitiTypeController {

    private static final Logger logger = LoggerFactory.getLogger(ActivitiTypeController.class);

    @Autowired
    private ActivitiTypeDubboService activitiTypeDubboService;

    @GetMapping("/list")
    @ApiOperation(value = "查询所有")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键", required = false, paramType = "query"),
            @ApiImplicitParam(name = "activitiTypeCode", value = "工作流Code", required = false, paramType = "query"),
            @ApiImplicitParam(name = "activitiTypeName", value = "工作流名称", required = false, paramType = "query")
    })
    public ApiResult list(ActivitiTypeVO activitiTypeVO) throws Exception {
        return ResponseUtil.ok(activitiTypeDubboService.listByVo(activitiTypeVO));
    }

    @GetMapping("/listCas")
    @ApiOperation(value = "查询所有")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "map", value = "当前公司id", required = true, paramType = "query")
    })
    public ApiResult<List<ActivitiTypeVO>> list(@RequestParam(required = false) Map<String, Object> map) throws Exception {
        return ResponseUtil.ok(activitiTypeDubboService.listCas(map));
    }

    @GetMapping("/page")
    @ApiOperation(value = "查询分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键", required = false, paramType = "query"),
            @ApiImplicitParam(name = "activitiTypeCode", value = "工作流Code", required = false, paramType = "query"),
            @ApiImplicitParam(name = "activitiTypeName", value = "工作流名称", required = false, paramType = "query"),
            @ApiImplicitParam(name = "pageNum", value = "页码", required = false, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = false, paramType = "query")
    })
    public ApiResult<PageInfo<ActivitiTypeVO>> page(ActivitiTypeVO activitiTypeVO, Integer pageNum, Integer pageSize) throws Exception {
        return ResponseUtil.ok(activitiTypeDubboService.findPageByVO(activitiTypeVO,pageNum,pageSize));
    }

    @GetMapping("/load")
    @ApiOperation(value = "读取单个")
    public ApiResult load(@RequestParam Long id) throws Exception{
        return ResponseUtil.ok(activitiTypeDubboService.getById(id));
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存信息")
    public ApiResult save(@RequestBody ActivitiTypeVO activitiTypeVO,@CurrentUser LoginInfo loginInfo) throws Exception {
        activitiTypeDubboService.saveOrUpdate(activitiTypeVO);
        return ResponseUtil.ok("success");
    }

    @PostMapping("/del")
    @ApiOperation(value = "删除")
    public ApiResult del(@RequestBody List<ActivitiTypeVO> activitiTypeVOList) throws Exception {
        activitiTypeDubboService.removeByListVo(activitiTypeVOList);
        return ResponseUtil.ok("success");
    }


}
